import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @author gao
 * @date 2025/11/5 21:28
 */

public class Solution {

    boolean[] checkCol, checkDg1, checkDg2;
    List<List<String>> ret;
    char[][] path;
    int m;

    public List<List<String>> solveNQueens(int n) {
        m = n;
        checkCol = new boolean[n];
        checkDg1 = new boolean[n * 2];
        checkDg2 = new boolean[n * 2];
        ret = new ArrayList<>();
        path = new char[n][n];

        for (int i = 0; i < n; i++) {
            Arrays.fill(path[i], '.');
        }

        dfs(0);
        return ret;
    }

    private void dfs(int row) {
        // 递归终止条件：如果已经处理完所有行，将当前解添加到结果列表中
        if (row == m) {
            List<String> tmp = new ArrayList<>();
            // 将当前路径中的棋盘状态转换为为字符串列表
            for (int i = 0; i < m; i++) {
                tmp.add(new String(path[i]));
            }
            ret.add(new ArrayList<>(tmp));
        }

        // 遍历当前行的所有列
        for (int col = 0; col < m; col++) {
            // 两个对角线是否有皇后
            if (!checkCol[col] && !checkDg1[row - col + m] && !checkDg2[row + col]) {
                // 放置皇后
                path[row][col] = 'Q';
                // 标记该列和对角线已被占用
                checkCol[col] = checkDg1[row - col + m] = checkDg2[row + col] = true;
                dfs(row + 1);
                // 回溯，移除皇后
                path[row][col] = '.';
                checkCol[col] = checkDg1[row - col + m] = checkDg2[row + col] = false;
            }
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            Solution solution = new Solution();
            System.out.println(solution.solveNQueens(n));
        }
    }
}